<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="http://java.sun.com/jsp/jstl/core"%>

<%@ include file="../../../../header.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link
	href="<%=basePath%>statics/resources/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css"
	rel="stylesheet">
<link href="<%=basePath%>bootstrap/css/bootstrap.min.css"
	rel="stylesheet">

<script
	src="<%=basePath%>statics/resources/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="<%=basePath%>bootstrap/js/bootstrap.min.js"></script>
<script
	src="<%=basePath%>statics/resources/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
</head>
<body style="align: center;">
	<div style="margin-top: 10px; margin-left: 30px;">
		<form id="manage-form" action="" class="nice-validator n-yellow"
			novalidate="novalidate" _lpchecked="1">

			<div id="base-form">

				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">变动人员</label>
						</div>
						<div class="ctn-wrap">

							<select style="width: 210px; height: auto;" class="ui-input"
								name="personId" id="personId">
								<s:forEach items="${User}" var="user">
									<option value="${user.id }">${user.username }</option>
								</s:forEach>
							</select>
						</div>
					</li>
				</ul>

				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">变动类型</label>
						</div>
						<div class="ctn-wrap">

							<select style="width: 210px; height: auto;" class="ui-input"
								name="changeType" id="changeType">

								<option value="1">转正</option>
								<option value="2">部门变动</option>
								<option value="3">离职</option>
							</select>
						</div>
					</li>
				</ul>

				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">变动前：</label>
						</div>
						<div class="ctn-wrap">
							<input value="" class="ui-input" name="days" id="days"
								autocomplete="off" aria-required="true" type="text">
						</div>
					</li>
				</ul>
				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">变动后：</label>
						</div>
						<div class="ctn-wrap">
							<input value="" class="ui-input" name="days" id="days"
								autocomplete="off" aria-required="true" type="text">
						</div>
					</li>
				</ul>
				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">生效时间</label>
						</div>
						<div class="ctn-wrap">
							<input value="" class="ui-input" name="effectDate" id="effectDate"
								type="text">
						</div>
					</li>
				</ul>
			</div>
		</form>
	</div>

	<script type="text/javascript">
		function initDate(effectDateId) {
			var effectDateValue;
			effectDateId = "#" + effectDateId;
			$(effectDateId).datetimepicker({
				format : 'yyyy-mm-dd hh:ii:ss',
				language : "zh-CN",
				todayHighlight : true,
				autoclose : true,
				todayBtn : true,
				minDate : 0,
				onChangeDateTime : function(dp, $input) {
					effectDateValue = $(effectDateId).val();
				}
			});
		}

		var api = frameElement.api;
		var operate = api.data.operate;
		var rowid = api.data.rowid;
		var rowdata = api.data.rowdata;
		var CallBack = api.data.callback;

		initDate('effectDate');

		$(function() {
			initPopBtns();
			if (operate == "edit" || operate == "view") {
				$("#startTime").val(rowdata.startTime);
				$("#endTime").val(rowdata.endTime);
				$("#remark").val(rowdata.remark);
				$("#days").val(rowdata.days);
				if (rowdata.picture.indexOf("<img src") == -1) {
					$("#picture").val(rowdata.picture);
				}
				$("#qingJiaTypeId option[value=" + rowdata.qingJiaTypeId + "]")
						.attr('selected', true);
				$("#personId option[value=" + rowdata.personId + "]").attr(
						'selected', true);

			}
		})
		function initPopBtns() {
			if ("view" == operate) {
				api.button({
					id : "cancel",
					name : "关闭"
				})
				return;
			}

			var btnname = "add" == operate ? [ "保存", "关闭" ] : [ "确定", "取消" ];

			api.button({
				id : "confirm",
				name : btnname[0],
				focus : true,
				callback : function(e) {
					var formData = new FormData();

					var uploadFile = $('#file').get(0).files[0];
					formData.append("file", uploadFile || 0);
					formData.append("id", rowid || 0);
					formData.append("startTime", $("#startTime").val());
					formData.append("endTime", $("#endTime").val());
					formData.append("remark", $("#remark").val());
					formData.append("days", $("#days").val());
					formData.append("picture", $("#picture").val());
					formData.append("qingJiaTypeId", $(
							'#qingJiaTypeId option:selected').attr('value'));
					formData.append("personId", $('#personId option:selected')
							.attr('value'));

					var re = true;
					if (operate == "add") {
						$.ajax({
							url : 'askleave/add',
							type : 'POST',
							dataType : "json",
							data : formData,
							async : false,
							cache : false,
							contentType : false, //不设置内容类型  
							processData : false, //不处理数据  
							success : function(data) {
								console.log(data);
								if (data.status == 200) {
									parent.Public.tips({
										content : "添加成功"
									})
									CallBack();
								} else {
									parent.Public.tips({
										type : 1,
										content : "添加失败:" + data.message
									});
									re = false;
								}
							},
							error : function(XMLHttpRequest, textStatus,
									errorThrown) {
								// 状态码
								console.log(XMLHttpRequest.status);
								// 状态
								console.log(XMLHttpRequest.readyState);
								// 错误信息   
								console.log(textStatus);
							}
						});
					} else {
						$.ajax({
							url : "askleave/edit",
							type : "POST",
							dataType : "json",
							data : formData,
							async : false,
							cache : false,
							contentType : false, //不设置内容类型  
							processData : false, //不处理数据  
							success : function(data) {
								if (data.status == 200) {
									parent.Public.tips({
										content : "修改成功"
									})
									CallBack();
								} else {
									parent.Public.tips({
										type : 1,
										content : "修改失败:" + data.message
									});
									re = false;
								}
							}
						});
					}
					return re;
				}
			}, {
				id : "cancel",
				name : btnname[1]
			})
		}
	</script>
</body>
</html>